package com.example.bookdemo.model;

import com.example.bookdemo.enums.ResultEnum;
import lombok.Data;

@Data
public class Result<T> {
    private int code;//返回操作码
    private String errorMSG;
    private T data;//记录数据

    public static <T> Result<T> noLogin(){
        Result result = new Result<>();
        result.setCode(ResultEnum.NO_LOGIN.getCode());
        result.setErrorMSG("用户没有登录");
        return result;
    }

    public static <T> Result<T> success(T data){
        Result result = new Result<>();
        result.setCode(ResultEnum.SUCCESS.getCode());
        result.setErrorMSG("");
        result.setData(data);
        return result;
    }

    public static <T> Result<T> fail(int code ,String msg){
        Result result = new Result<>();
        result.setErrorMSG(msg);
        result.setCode(code);
        result.setData(null);
        return result;
    }
}
